require "utils"
require "pm"
require "pins"
require "aLiCMD"

module(..., package.seeall)

local get_power = pins.setup(pio.P0_25)

-- 断电报警任务
sys.taskInit(function()
    local power_state = 0
    while true do
        sys.wait(10)
        -- log.info("SIG", get_sig())
       
        if get_power() == 0 and power_state == 0 then
            sys.wait(5000)
            if get_power() == 0 and power_state == 0 then
                aLiCMD.eventPost("POWER OFF")
                aLiCMD.poweroff()
                power_state = 1
                sys.publish("POWER_STATE", 1)
            end
        elseif get_power() == 1 and power_state == 1 then
            sys.wait(5000)
            if get_power() == 1 and power_state == 1 then
                power_state = 0
                aLiCMD.eventPost("POWER ON")
                aLiCMD.onceStart()
                sys.publish("POWER_STATE", 0)
            end
        end
    end
end)
